home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / sndfile.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-12-20  |  15.7 KB  |  492 lines

  1. /*
  2. ** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU Lesser General Public License as published by
  6. ** the Free Software Foundation; either version 2.1 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU Lesser General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU Lesser General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. /*
  20. ** sndfile.h -- system-wide definitions
  21. **
  22. ** API documentation is in the doc/ directory of the source code tarball
  23. ** and at http://www.mega-nerd.com/libsndfile/api.html.
  24. */
  25.  
  26. #ifndef SNDFILE_H
  27. #define SNDFILE_H
  28.  
  29. /* This is the version 1.0.X header file. */
  30. #define    SNDFILE_1
  31.  
  32. #include <stdio.h>
  33.  
  34. /* For the Metrowerks CodeWarrior Pro Compiler (mainly MacOS) */
  35.  
  36. #if    (defined (__MWERKS__))
  37. #include    <unix.h>
  38. #else
  39. #include    <sys/types.h>
  40. #endif
  41.  
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif    /* __cplusplus */
  45.  
  46. /* The following file types can be read and written.
  47. ** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
  48. ** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
  49. ** SF_FORMAT_SUBMASK can be used to separate the major and minor file
  50. ** types.
  51. */
  52.  
  53. enum
  54. {    /* Major formats. */
  55.     SF_FORMAT_WAV            = 0x010000,        /* Microsoft WAV format (little endian). */
  56.     SF_FORMAT_AIFF            = 0x020000,        /* Apple/SGI AIFF format (big endian). */
  57.     SF_FORMAT_AU            = 0x030000,        /* Sun/NeXT AU format (big endian). */
  58.     SF_FORMAT_RAW            = 0x040000,        /* RAW PCM data. */
  59.     SF_FORMAT_PAF            = 0x050000,        /* Ensoniq PARIS file format. */
  60.     SF_FORMAT_SVX            = 0x060000,        /* Amiga IFF / SVX8 / SV16 format. */
  61.     SF_FORMAT_NIST            = 0x070000,        /* Sphere NIST format. */
  62.     SF_FORMAT_VOC            = 0x080000,        /* VOC files. */
  63.     SF_FORMAT_IRCAM            = 0x0A0000,        /* Berkeley/IRCAM/CARL */
  64.     SF_FORMAT_W64            = 0x0B0000,        /* Sonic Foundry's 64 bit RIFF/WAV */
  65.     SF_FORMAT_MAT4            = 0x0C0000,        /* Matlab (tm) V4.2 / GNU Octave 2.0 */
  66.     SF_FORMAT_MAT5            = 0x0D0000,        /* Matlab (tm) V5.0 / GNU Octave 2.1 */
  67.     SF_FORMAT_PVF            = 0x0E0000,        /* Portable Voice Format */
  68.     SF_FORMAT_XI            = 0x0F0000,        /* Fasttracker 2 Extended Instrument */
  69.     SF_FORMAT_HTK            = 0x100000,        /* HMM Tool Kit format */
  70.     SF_FORMAT_SDS            = 0x110000,        /* Midi Sample Dump Standard */
  71.     SF_FORMAT_AVR            = 0x120000,        /* Audio Visual Research */
  72.     SF_FORMAT_WAVEX            = 0x130000,        /* MS WAVE with WAVEFORMATEX */
  73.     SF_FORMAT_SD2            = 0x160000,        /* Sound Designer 2 */
  74.  
  75.     /* Subtypes from here on. */
  76.  
  77.     SF_FORMAT_PCM_S8        = 0x0001,        /* Signed 8 bit data */
  78.     SF_FORMAT_PCM_16        = 0x0002,        /* Signed 16 bit data */
  79.     SF_FORMAT_PCM_24        = 0x0003,        /* Signed 24 bit data */
  80.     SF_FORMAT_PCM_32        = 0x0004,        /* Signed 32 bit data */
  81.  
  82.     SF_FORMAT_PCM_U8        = 0x0005,        /* Unsigned 8 bit data (WAV and RAW only) */
  83.  
  84.     SF_FORMAT_FLOAT            = 0x0006,        /* 32 bit float data */
  85.     SF_FORMAT_DOUBLE        = 0x0007,        /* 64 bit float data */
  86.  
  87.     SF_FORMAT_ULAW            = 0x0010,        /* U-Law encoded. */
  88.     SF_FORMAT_ALAW            = 0x0011,        /* A-Law encoded. */
  89.     SF_FORMAT_IMA_ADPCM        = 0x0012,        /* IMA ADPCM. */
  90.     SF_FORMAT_MS_ADPCM        = 0x0013,        /* Microsoft ADPCM. */
  91.  
  92.     SF_FORMAT_GSM610        = 0x0020,        /* GSM 6.10 encoding. */
  93.     SF_FORMAT_VOX_ADPCM        = 0x0021,        /* OKI / Dialogix ADPCM */
  94.  
  95.     SF_FORMAT_G721_32        = 0x0030,        /* 32kbs G721 ADPCM encoding. */
  96.     SF_FORMAT_G723_24        = 0x0031,        /* 24kbs G723 ADPCM encoding. */
  97.     SF_FORMAT_G723_40        = 0x0032,        /* 40kbs G723 ADPCM encoding. */
  98.  
  99.     SF_FORMAT_DWVW_12        = 0x0040,         /* 12 bit Delta Width Variable Word encoding. */
  100.     SF_FORMAT_DWVW_16        = 0x0041,         /* 16 bit Delta Width Variable Word encoding. */
  101.     SF_FORMAT_DWVW_24        = 0x0042,         /* 24 bit Delta Width Variable Word encoding. */
  102.     SF_FORMAT_DWVW_N        = 0x0043,         /* N bit Delta Width Variable Word encoding. */
  103.  
  104.     SF_FORMAT_DPCM_8        = 0x0050,        /* 8 bit differential PCM (XI only) */
  105.     SF_FORMAT_DPCM_16        = 0x0051,        /* 16 bit differential PCM (XI only) */
  106.  
  107.  
  108.     /* Endian-ness options. */
  109.  
  110.     SF_ENDIAN_FILE            = 0x00000000,    /* Default file endian-ness. */
  111.     SF_ENDIAN_LITTLE        = 0x10000000,    /* Force little endian-ness. */
  112.     SF_ENDIAN_BIG            = 0x20000000,    /* Force big endian-ness. */
  113.     SF_ENDIAN_CPU            = 0x30000000,    /* Force CPU endian-ness. */
  114.  
  115.     SF_FORMAT_SUBMASK        = 0x0000FFFF,
  116.     SF_FORMAT_TYPEMASK        = 0x0FFF0000,
  117.     SF_FORMAT_ENDMASK        = 0x30000000
  118. } ;
  119.  
  120. /*
  121. ** The following are the valid command numbers for the sf_command()
  122. ** interface.  The use of these commands is documented in the file
  123. ** command.html in the doc directory of the source code distribution.
  124. */
  125.  
  126. enum
  127. {    SFC_GET_LIB_VERSION                = 0x1000,
  128.     SFC_GET_LOG_INFO                = 0x1001,
  129.  
  130.     SFC_GET_NORM_DOUBLE                = 0x1010,
  131.     SFC_GET_NORM_FLOAT                = 0x1011,
  132.     SFC_SET_NORM_DOUBLE                = 0x1012,
  133.     SFC_SET_NORM_FLOAT                = 0x1013,
  134.     SFC_SET_SCALE_FLOAT_INT_READ    = 0x1014,
  135.  
  136.     SFC_GET_SIMPLE_FORMAT_COUNT        = 0x1020,
  137.     SFC_GET_SIMPLE_FORMAT            = 0x1021,
  138.  
  139.     SFC_GET_FORMAT_INFO                = 0x1028,
  140.  
  141.     SFC_GET_FORMAT_MAJOR_COUNT        = 0x1030,
  142.     SFC_GET_FORMAT_MAJOR            = 0x1031,
  143.     SFC_GET_FORMAT_SUBTYPE_COUNT    = 0x1032,
  144.     SFC_GET_FORMAT_SUBTYPE            = 0x1033,
  145.  
  146.     SFC_CALC_SIGNAL_MAX                = 0x1040,
  147.     SFC_CALC_NORM_SIGNAL_MAX        = 0x1041,
  148.     SFC_CALC_MAX_ALL_CHANNELS        = 0x1042,
  149.     SFC_CALC_NORM_MAX_ALL_CHANNELS    = 0x1043,
  150.  
  151.     SFC_SET_ADD_PEAK_CHUNK            = 0x1050,
  152.  
  153.     SFC_UPDATE_HEADER_NOW            = 0x1060,
  154.     SFC_SET_UPDATE_HEADER_AUTO        = 0x1061,
  155.  
  156.     SFC_FILE_TRUNCATE                = 0x1080,
  157.  
  158.     SFC_SET_RAW_START_OFFSET        = 0x1090,
  159.  
  160.     SFC_SET_DITHER_ON_WRITE            = 0x10A0,
  161.     SFC_SET_DITHER_ON_READ            = 0x10A1,
  162.  
  163.     SFC_GET_DITHER_INFO_COUNT        = 0x10A2,
  164.     SFC_GET_DITHER_INFO                = 0x10A3,
  165.  
  166.     SFC_GET_EMBED_FILE_INFO            = 0x10B0,
  167.  
  168.     SFC_SET_CLIPPING                = 0x10C0,
  169.     SFC_GET_CLIPPING                = 0x10C1,
  170.  
  171.     SFC_GET_INSTRUMENT                = 0x10D0,
  172.     SFC_SET_INSTRUMENT                = 0x10D1,
  173.  
  174.     SFC_GET_LOOP_INFO                = 0x10E0,
  175.  
  176.     /* Following commands for testing only. */
  177.     SFC_TEST_IEEE_FLOAT_REPLACE        = 0x6001,
  178.  
  179.     /*
  180.     ** SFC_SET_ADD_* values are deprecated and will disappear at some
  181.     ** time in the future. They are guaranteed to be here up to and
  182.     ** including version 1.0.8 to avoid breakage of existng software.
  183.     ** They currently do nothing and will continue to do nothing.
  184.     */
  185.     SFC_SET_ADD_DITHER_ON_WRITE        = 0x1070,
  186.     SFC_SET_ADD_DITHER_ON_READ        = 0x1071
  187. } ;
  188.  
  189.  
  190. /*
  191. ** String types that can be set and read from files. Not all file types
  192. ** support this and even the file types which support one, may not support
  193. ** all string types.
  194. */
  195.  
  196. enum
  197. {    SF_STR_TITLE                    = 0x01,
  198.     SF_STR_COPYRIGHT                = 0x02,
  199.     SF_STR_SOFTWARE                    = 0x03,
  200.     SF_STR_ARTIST                    = 0x04,
  201.     SF_STR_COMMENT                    = 0x05,
  202.     SF_STR_DATE                        = 0x06
  203. } ;
  204.  
  205. /*
  206. ** Use the following as the start and end index when doing metadata
  207. ** transcoding.
  208. */
  209.  
  210. #define    SF_STR_FIRST    SF_STR_TITLE
  211. #define    SF_STR_LAST        SF_STR_DATE
  212.  
  213. enum
  214. {    /* True and false */
  215.     SF_FALSE    = 0,
  216.     SF_TRUE        = 1,
  217.  
  218.     /* Modes for opening files. */
  219.     SFM_READ    = 0x10,
  220.     SFM_WRITE    = 0x20,
  221.     SFM_RDWR    = 0x30
  222. } ;
  223.  
  224. /* Public error values. These are guaranteed to remain unchanged for the duration
  225. ** of the library major version number.
  226. ** There are also a large number of private error numbers which are internal to
  227. ** the library which can change at any time.
  228. */
  229.  
  230. enum
  231. {    SF_ERR_NO_ERROR                = 0,
  232.     SF_ERR_UNRECOGNISED_FORMAT    = 1,
  233.     SF_ERR_SYSTEM                = 2
  234. } ;
  235.  
  236. /* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
  237.  
  238. typedef    struct SNDFILE_tag    SNDFILE ;
  239.  
  240. /* The following typedef is system specific and is defined when libsndfile is.
  241. ** compiled. sf_count_t can be one of loff_t (Linux), off_t (*BSD),
  242. ** off64_t (Solaris), __int64_t (Win32) etc.
  243. */
  244.  
  245. typedef loff_t    sf_count_t ;
  246.  
  247. #define SF_COUNT_MAX        0x7FFFFFFFFFFFFFFFLL
  248.  
  249. /* A pointer to a SF_INFO structure is passed to sf_open_read () and filled in.
  250. ** On write, the SF_INFO structure is filled in by the user and passed into
  251. ** sf_open_write ().
  252. */
  253.  
  254. struct SF_INFO
  255. {    sf_count_t    frames ;        /* Used to be called samples.  Changed to avoid confusion. */
  256.     int            samplerate ;
  257.     int            channels ;
  258.     int            format ;
  259.     int            sections ;
  260.     int            seekable ;
  261. } ;
  262.  
  263. typedef    struct SF_INFO SF_INFO ;
  264.  
  265. /* The SF_FORMAT_INFO struct is used to retrieve information about the sound
  266. ** file formats libsndfile supports using the sf_command () interface.
  267. **
  268. ** Using this interface will allow applications to support new file formats
  269. ** and encoding types when libsndfile is upgraded, without requiring
  270. ** re-compilation of the application.
  271. **
  272. ** Please consult the libsndfile documentation (particularly the information
  273. ** on the sf_command () interface) for examples of its use.
  274. */
  275.  
  276. typedef struct
  277. {    int            format ;
  278.     const char    *name ;
  279.     const char    *extension ;
  280. } SF_FORMAT_INFO ;
  281.  
  282. /*
  283. ** Enums and typedefs for adding dither on read and write.
  284. ** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
  285. ** and SFC_SET_DITHER_ON_READ.
  286. */
  287.  
  288. enum
  289. {    SFD_DEFAULT_LEVEL    = 0,
  290.     SFD_CUSTOM_LEVEL    = 0x40000000,
  291.  
  292.     SFD_NO_DITHER        = 500,
  293.     SFD_WHITE            = 501,
  294.     SFD_TRIANGULAR_PDF    = 502
  295. } ;
  296.  
  297. typedef struct
  298. {    int            type ;
  299.     double        level ;
  300.     const char    *name ;
  301. } SF_DITHER_INFO ;
  302.  
  303. /* Struct used to retrieve information about a file embedded within a
  304. ** larger file. See SFC_GET_EMBED_FILE_INFO.
  305. */
  306.  
  307. typedef struct
  308. {    sf_count_t    offset ;
  309.     sf_count_t    length ;
  310. } SF_EMBED_FILE_INFO ;
  311.  
  312. /* Struct used to retrieve music sample information from a file.
  313. */
  314.  
  315. typedef struct
  316. {    int basenote ;
  317.     int gain ;
  318.     int    sustain_mode ;
  319.     int sustain_start, sustain_end ;
  320.     int release_mode ;
  321.     int release_start, reslease_end ;
  322. } SF_INSTRUMENT ;
  323.  
  324. /* sustain_mode and release_mode will be one of the following. */
  325.  
  326. enum
  327. {    SF_LOOP_NONE = 800,
  328.     SF_LOOP_FORWARD,
  329.     SF_LOOP_BACKWARD
  330. } ;
  331.  
  332. /* Struct used to retrieve loop information from a file.*/
  333. typedef struct
  334. {
  335.     short    time_sig_num ;    /* any positive integer    >0  */
  336.     short    time_sig_den ;    /* any positive power of 2 >0  */
  337.     int        loop_mode ;        /* see SF_LOOP enum            */
  338.  
  339.     int        num_beats ;        /* this is NOT the amount of quarter notes !!!*/
  340.                             /* a full bar of 4/4 is 4 beats */
  341.                             /* a full bar of 7/8 is 7 beats */
  342.  
  343.     float    bpm ;            /* suggestion, as it can be calculated using other fields:*/
  344.                             /* file's lenght, file's sampleRate and our time_sig_den*/
  345.                             /* -> bpms are always the amount of _quarter notes_ per minute */
  346.  
  347.     int    root_key ;            /* MIDI note, or -1 for None */
  348.     int future [6] ;
  349. } SF_LOOP_INFO ;
  350.  
  351. /* Open the specified file for read, write or both. On error, this will
  352. ** return a NULL pointer. To find the error number, pass a NULL SNDFILE
  353. ** to sf_perror () or sf_error_str ().
  354. ** All calls to sf_open() should be matched with a call to sf_close().
  355. */
  356.  
  357. SNDFILE*     sf_open        (const char *path, int mode, SF_INFO *sfinfo) ;
  358.  
  359. /* Use the existing file descriptor to create a SNDFILE object. If close_desc
  360. ** is TRUE, the file descriptor will be closed when sf_close() is called. If
  361. ** it is FALSE, the descritor will not be closed.
  362. ** When passed a descriptor like this, the library will assume that the start
  363. ** of file header is at the current file offset. This allows sound files within
  364. ** larger container files to be read and/or written.
  365. ** On error, this will return a NULL pointer. To find the error number, pass a
  366. ** NULL SNDFILE to sf_perror () or sf_error_str ().
  367. ** All calls to sf_open_fd() should be matched with a call to sf_close().
  368.  
  369. */
  370.  
  371. SNDFILE*     sf_open_fd    (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
  372.  
  373. /* sf_error () returns a error number which can be translated to a text
  374. ** string using sf_error_number().
  375. */
  376.  
  377. int        sf_error        (SNDFILE *sndfile) ;
  378.  
  379. /* sf_strerror () returns to the caller a pointer to the current error message for
  380. ** the given SNDFILE.
  381. */
  382.  
  383. const char* sf_strerror (SNDFILE *sndfile) ;
  384.  
  385. /* sf_error_number () allows the retrieval of the error string for each internal
  386. ** error number.
  387. **
  388. */
  389.  
  390. const char*    sf_error_number    (int errnum) ;
  391.  
  392. /* The following three error functions are deprecated but they will remain in the
  393. ** library for the forseeable future. The function sf_strerror() should be used
  394. ** in their place.
  395. */
  396.  
  397. int        sf_perror        (SNDFILE *sndfile) ;
  398. int        sf_error_str    (SNDFILE *sndfile, char* str, size_t len) ;
  399.  
  400.  
  401. /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
  402.  
  403. int        sf_command    (SNDFILE *sndfile, int command, void *data, int datasize) ;
  404.  
  405. /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
  406.  
  407. int        sf_format_check    (const SF_INFO *info) ;
  408.  
  409. /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses
  410. ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as
  411. ** stdio.h function fseek ().
  412. ** An offset of zero with whence set to SEEK_SET will position the
  413. ** read / write pointer to the first data sample.
  414. ** On success sf_seek returns the current position in (multi-channel)
  415. ** samples from the start of the file.
  416. ** Please see the libsndfile documentation for moving the read pointer
  417. ** separately from the write pointer on files open in mode SFM_RDWR.
  418. ** On error all of these functions return -1.
  419. */
  420.  
  421. sf_count_t    sf_seek         (SNDFILE *sndfile, sf_count_t frames, int whence) ;
  422.  
  423. /* Functions for retrieving and setting string data within sound files.
  424. ** Not all file types support this features; AIFF and WAV do. For both
  425. ** functions, the str_type parameter must be one of the SF_STR_* values
  426. ** defined above.
  427. ** On error, sf_set_string() returns non-zero while sf_get_string()
  428. ** returns NULL.
  429. */
  430.  
  431. int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
  432.  
  433. const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
  434.  
  435. /* Functions for reading/writing the waveform data of a sound file.
  436. */
  437.  
  438. sf_count_t    sf_read_raw        (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
  439. sf_count_t    sf_write_raw     (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
  440.  
  441. /* Functions for reading and writing the data chunk in terms of frames.
  442. ** The number of items actually read/written = frames * number of channels.
  443. **     sf_xxxx_raw        read/writes the raw data bytes from/to the file
  444. **     sf_xxxx_short    passes data in the native short format
  445. **     sf_xxxx_int        passes data in the native int format
  446. **     sf_xxxx_float    passes data in the native float format
  447. **     sf_xxxx_double    passes data in the native double format
  448. ** All of these read/write function return number of frames read/written.
  449. */
  450.  
  451. sf_count_t    sf_readf_short    (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
  452. sf_count_t    sf_writef_short    (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
  453.  
  454. sf_count_t    sf_readf_int    (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
  455. sf_count_t    sf_writef_int     (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
  456.  
  457. sf_count_t    sf_readf_float    (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
  458. sf_count_t    sf_writef_float    (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
  459.  
  460. sf_count_t    sf_readf_double        (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
  461. sf_count_t    sf_writef_double    (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
  462.  
  463. /* Functions for reading and writing the data chunk in terms of items.
  464. ** Otherwise similar to above.
  465. ** All of these read/write function return number of items read/written.
  466. */
  467.  
  468. sf_count_t    sf_read_short    (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
  469. sf_count_t    sf_write_short    (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
  470.  
  471. sf_count_t    sf_read_int        (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
  472. sf_count_t    sf_write_int     (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
  473.  
  474. sf_count_t    sf_read_float    (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
  475. sf_count_t    sf_write_float    (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
  476.  
  477. sf_count_t    sf_read_double    (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
  478. sf_count_t    sf_write_double    (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
  479.  
  480. /* Close the SNDFILE and clean up all memory allocations associated with this
  481. ** file.
  482. ** Returns 0 on success, or an error number.
  483. */
  484.  
  485. int        sf_close        (SNDFILE *sndfile) ;
  486.  
  487. #ifdef __cplusplus
  488. }        /* extern "C" */
  489. #endif    /* __cplusplus */
  490.  
  491. #endif    /* SNDFILE_H */
  492.